<?php

namespace Models;

class Wx extends BaseModel {

    public function initialize()
    {
        $this->hasMany("token", "Models\WxImg", "token", array('alias' => 'WxImg'));
        $this->hasMany("token", "Models\Act", "token", array('alias' => 'Act'));
//        $this->belongsTo("token", "WxText", "token");
//        $this->belongsTo("token", "WxKeyword", "token");
//        $this->belongsTo("token", "WxAreply", "token");
    }
    public function notSave()
    {
        //Obtain the flash service from the DI container
        $flash = $this->getDI()->getFlash();

        //Show validation messages
        foreach ($this->getMessages() as $message) {
            $flash->error($message);
        }
    }

    public function get_token(){
        $randLength=6;
        $chars='abcdefghijklmnopqrstuvwxyz';
        $len=strlen($chars);
        $randStr='';
        for ($i=0;$i<$randLength;$i++){
            $randStr.=$chars[rand(0,$len-1)];
        }
        $tokenvalue=$randStr.time();
        return $tokenvalue;
    }
}